/*
 * 文件名： VehicleLoginData.java
 * 
 * 创建日期： 2016年12月6日
 *
 * Copyright(C) 2016,0x by <a href="mailto:liws@xingyuanauto.com">liws</a>.
 *
 * 原始作者: liws
 *
 */
package com.moli.iov.protocol.model;

import java.util.Arrays;

import com.moli.iov.protocol.codec.DataDecoder;
import com.moli.iov.protocol.codec.Serialize;
import com.moli.iov.protocol.enums.DateTimeTag;
import com.moli.iov.util.ByteArrayUtil;



/**
 * 车辆登入数据 实体
 *
 * @author <a href="mailto:liws@xingyuanauto.com">liws</a>
 *
 * @version $Revision$
 *
 * @since 2016年12月6日
 */
@Serialize(unit = "byte", isBigEndian = true)
public class VehicleLoginReq extends Header implements EntityBytesLen{
	
	/** 
	*/
	private static final long serialVersionUID = 1L;
	
	private int bytesLen = 28;
	 /**
	 *
	 */
	@Override
	public int getBytesLen() {
		return bytesLen;
	}
	/**
	 * 数据采集时间
	 */
	@Serialize(unit = "byte", offset = header_offset + 0, size = 6)
	public DateTimeTag collectDate;
	
	/**
	 * 流水号
	 */
	@Serialize(unit = "byte", offset = header_offset + 6, size = 2)
	public short serialNum;

	/**
	 * ICCID 需调用ascii转换 ByteArrayUtil.strToAscii()
	 */
	@Serialize(unit = "byte", offset = header_offset + 8, size = 20)
	public String iccid;

	/**
	 * 可充电储能子系统数
	 */
	@Serialize(unit = "byte", offset = header_offset + 28, size = 1)
	public int sysSum;

	/**
	 * 可充电储能系统编码长度
	 */
	@Serialize(unit = "byte", offset = header_offset + 29, size = 1)
	public short sysCodeLen = 0;

	/**
	 * 可充电储能系统编码
	 */
	public byte[] sysCode;

	/**
	 * 由于此报文中间序列存在变长字段,0x后续属性无法确定偏移量(offset)和字节序长度(size)
	 * 故采用在第一个变长属性方法中设置后续所有属性的注解方式. 注意:需要保证变长字段获偏移量和size 故采用排序解码方式,0x
	 * 
	 * @return
	 */
	public byte[] getSysCode() {

		return sysCode;
	}
    
    /**
	*
	* @return the collectDate
	*/
	
	public DateTimeTag getCollectDate() {
		return collectDate;
	}


	/**
	*
	* @param collectDate the collectDate to set
	*/
	public void setCollectDate(DateTimeTag collectDate) {
		this.collectDate = collectDate;
	}


	/**
     * @return the serialNum
     */
    public short getSerialNum() {
        return serialNum;
    }
    
    /**
     * @param serialNum the serialNum to set
     */
    public void setSerialNum(short serialNum) {
        this.serialNum = serialNum;
    }

    /**
     * @return the iccid
     */
    public String getIccid() {
        return iccid;
    }
    
    /**
     * @param iccid the iccid to set
     */
    public void setIccid(String iccid) {
        this.iccid = iccid;
    }
    
    /**
     * @return the sysSum
     */
    public int getSysSum() {
        return sysSum;
    }
    
    /**
	*
	* @return the sysCodeLen
	*/
	
	public short getSysCodeLen() {
		return sysCodeLen;
	}

	/**
	*
	* @param sysCodeLen the sysCodeLen to set
	*/
	public void setSysCodeLen(short sysCodeLen) {
		this.sysCodeLen = sysCodeLen;
	}

	/**
	*
	* @param sysSum the sysSum to set
	*/
	public void setSysSum(int sysSum) {
		this.sysSum = sysSum;
	}

	/**
     * @param sysCodeLen the sysCodeLen to set
     */
    public void setSysCodeLen(byte sysCodeLen) {
        this.sysCodeLen = sysCodeLen;
    }
    /**
     * @param bytesLen the bytesLen to set
     */
    public void setBytesLen(int bytesLen) {
        this.bytesLen = bytesLen;
    }
    
    /**
     * @param sysCode the sysCode to set
     */
    @Serialize(unit = "byte", offset = header_offset + 30, size = -1)
    public void setSysCode(byte[] sysCode) {
    	this.sysCode = new byte[this.sysCodeLen];
        System.arraycopy(sysCode, 0, this.sysCode, 0, this.sysCodeLen);
    }

    /**
	 *
	 * @see java.lang.Object#toString()
	 */


	public static void main(String[] args) {
		byte[] bytes = new byte[]
			{0x23,0x23,0x01,(byte)0xfe,0x4c,0x4c,0x56,0x32,0x41,
					0x52,0x42,0x32,0x35,0x47,0x31,0x35,0x30,0x30,
					0x30,0x30,0x30,0x01,0x00,0x2a,0x11,0x03,0x0f,0x0f,
					0x22,0x10,0x00,0x16,0x38,0x39,0x38,0x36,0x30,0x32,
					0x42,0x33,0x32,0x32,0x31,0x35,0x33,0x30,0x30,0x33,0x30,0x35,0x37
					,0x38,0x01,0x0c,0x43,0x31,0x31,0x41,0x30,0x30
					,0x30,0x30,0x30,0x30,0x33,0x43,(byte)0xed};
		String hexString = "23 23 01 fe 4d 4d 56 32 41 52 42 32 35 47 30 30 31 32 36 39 37 01 00 2a 12 04 0a 10 21 32 00 1a 38 39 38 36 30 32 42 32 33 33 31 35 33 30 30 31 32 36 39 37 01 0c 43 31 31 41 30 30 30 30 30 30 33 43 91";
		bytes = ByteArrayUtil.hexStringToBytes(hexString);
		VehicleLoginReq vehicleLoginData = new VehicleLoginReq();
		DataDecoder<VehicleLoginReq> decoder = new DataDecoder<>();
		try {
			decoder.decode(vehicleLoginData, bytes);
		}
		catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		System.out.println(vehicleLoginData.toString());

	}

    /* (非 Javadoc)
     * Description:
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return "VehicleLoginReq [bytesLen=" + bytesLen + ", collectDate=" + collectDate + ", serialNum=" + serialNum
                + ", iccid=" + iccid + ", sysSum=" + sysSum + ", sysCodeLen=" + sysCodeLen + ", sysCode="
                + Arrays.toString(sysCode) + "]";
    }

}
